# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-coderay
pkgver=1.1.3
pkgrel=2
pkgdesc='Fast and easy syntax highlighting for selected languages'
arch=(any)
url='https://github.com/rubychan/coderay'
license=(MIT)
depends=(ruby)
checkdepends=(ruby-rake ruby-redcloth ruby-rspec ruby-shoulda-context ruby-simplecov
              ruby-term-ansicolor ruby-test-unit ruby-tins)
options=(!emptydirs)
source=(https://github.com/rubychan/coderay/archive/v$pkgver/$pkgname-$pkgver.tar.gz
        $pkgname-ruby-3.patch::https://github.com/rubychan/coderay/commit/c1c15034749684fcad91ad2bcb2fcd2056faf18d.patch)
sha256sums=('b69aa65951e5381fa807f347780030cfe557910427b5d26b9e0a309682186c8a'
            'c2ab034f01d4b4f2d16e5bef5de040edf4760d9828f9c5cefcd0372b0f6cbd57')

prepare() {
  cd coderay-$pkgver
  patch -p1 -i ../$pkgname-ruby-3.patch
  sed -e 's|git ls-files -- bin/\*|find bin -type f|' \
      -e 's|git ls-files -- lib/\* #{readme_file} MIT-LICENSE|find lib #{readme_file} MIT-LICENSE -type f|' \
      -i coderay.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd coderay-$pkgver
  RELEASE=1 gem build coderay.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    coderay-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd coderay-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd coderay-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 MIT-LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
